<?php
namespace app\service;

use app\models\Invoice_new;
use app\models\Income;
use app\models\Product_pay;
use app\models\Purchase_order;

class FinanceService
{
    public function month_income($m)
    {
        $model = new Invoice_new();
        $list = $model->get_invoice_by_month($m);
        $invoice_arr = [];
        foreach ($list as $v) {
            $invoice_arr[] = $v['invoice'];
        }
        $incomeModel = new Income();
        $list2 = $incomeModel->get_group_income_by_invoice($invoice_arr);
        foreach ($list as $k => $v) {
            $list[$k]['income'] = $list2[$v['invoice']]??"";
        }
        return $list;
    }

    //月度应付
    public function month_pay($where)
    {
        $model = new Product_pay();
        $list = $model->get_product_pay_list_by_month($where);
        $purcahse_order = [];
        foreach ($list as $v) {
            $purcahse_order[] = $v['purchase_order'];
        }
        $purchaseModel = new Purchase_order();
        $purcahse_list = $purchaseModel->get_list_by_purchase_order($purcahse_order);
        foreach ($list as $k => $v) {
            if (isset($purcahse_list[$v['purchase_order']])) {
                $list[$k]['status'] = $purcahse_list[$v['purchase_order']]['status'];
            } else {
                $list[$k]['status'] = 1;
            }
        }
        return $list;
    }
}
